/**
 * @author:  maybe
 * @date: 2024/1/17 
 * @des:  地址管理
 */
const mongoose = require('mongoose')
const Schema = mongoose.Schema; // 拿到当前数据库相应的集合对象
const {db} = require('../index')

// 设计地区表的集合
const addreesSchema = new Schema({ // 设计用户集合的字段以及数据类型
    name: { type: String },
    code:  { type: String },
    status: {
        type: Boolean,
        default: true
    },
    address: { type: String },
    province: { type: String },
    city: { type: String }, // ity
    area: { type: String },
    uid: {
        type: String
    },
    location: {
        type: Object
    }
},{ versionKey: false })
addreesSchema.set('toJSON', {
    virtuals: true
})

addreesSchema.options.toJSON = {
    transform(doc, ret, options) {
        ret.addressId = doc.id;
        delete ret._id;
        delete ret.__v;
        return ret;
    }
}

module.exports = db.model('addrees', addreesSchema);
